
#include <stdint.h>
#include "TIMER.h"

static int count = 0;
static int cval = 0;
static int access_tick = 0;

void _start();


/*需要加载到0x1FFF8000*/
__attribute__((section(".init0")))
uint32_t init_vecter[0x100] = {
    (uint32_t)_start,
    (uint32_t)_start,
};

//不需要处理栈
__attribute__( (optimize ("O2")))
__attribute__((section(".crt0")))
void _start(){
    __asm volatile(
        "ldr r1,=0x20000000+32*1024-4\n"        //32KB的sram
        "mov sp,r1\n"
        "bl init\n"
        "loop:\n"
        "b loop\n"
    );
}

__attribute__( (optimize ("O2")))
int _test_time(uint32_t*count,uint32_t *access){
    __asm volatile(
        "ldr r2,[r0]\n"
        "ldr r3,[r1]\n"
        "ldr r3,[r0]\n"
        "sub r0,r2,r3\n"
        "bx lr\n"
    );
}

void init(){
    TIMER1 = (TIMER1_BASE);
    *(int*)0x40016000 = 0x1;    //使能外设AHB
    timer_start1(TIMER1);
    while(1){
        count++;
        access_tick = _test_time(&TIMER1->timer1Value,0x60000000);
        cval = TIMER1->timer1Value;
    }
}
